//
//  ListenSongsFindSongerViewController.m
//  NewMusic
//
//  Created by chuxinyu123 on 15/11/25.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "ListenSongsFindSongerViewController.h"
#import "CustomerNetworking.h"
#import "Songer.h"
#import "PlayerViewController.h"
@interface ListenSongsFindSongerViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;

@end

@implementation ListenSongsFindSongerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //self.array = [NSMutableArray array];
    //[self createTableView];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, 50, 40);
    [button addTarget:self action:@selector(popAction:) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"icon_fanhui"] forState:UIControlStateNormal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
}

- (void)popAction:(UIButton *)button
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 5, 375, 600) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_tableView];
}
- (void)setArray:(NSMutableArray *)array
{
    if (_array != array) {
        [_array release];
        _array = [array retain];
    }
    [self createTableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"%ld", _array.count);
    return _array.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *string = @"listens";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:string];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:string];
    }
    cell.textLabel.text = [self.array[indexPath.row] name];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.detailTextLabel.text = [self.array[indexPath.row] singerName];
    cell.detailTextLabel.textColor = [UIColor whiteColor];
    cell.backgroundColor = [UIColor clearColor];
    [cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    PlayerViewController *player = [PlayerViewController sharePlayerViewController];
    NSMutableArray *arr = [NSMutableArray array];
    for (NSInteger i = 0; i < self.array.count; i++)
    {
        Songer *song = self.array[i];
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setValue:song.albumName forKey:@"album"];// 专辑
        [dic setValue:song.name forKey:@"name"]; // 歌名
        [dic setValue:song.auditionList forKey:@"music"]; // 歌曲,model用musicType
        [dic setValue:song.singerName forKey:@"songerName"];// 歌手名
        [dic setValue:song.albumId forKey:@"id"]; // id
        [arr addObject:dic];
    }
    player.musicArr = arr;
    [player MusicStart:indexPath.row];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
